﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UniversityStudentManagemnetSystem.BLL;
using UniversityStudentManagemnetSystem.DAO.DAL;

namespace UniversityStudentManagemnetSystem.UI
{
    public partial class ViewEmployeeInformation : System.Web.UI.Page
    {
        EmployeeManager manager = new EmployeeManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack != true)
            {
                searchButton.Enabled = false;
                searchButton.Visible = false;

            }
        }

        protected void DesignationRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            PopulatedDesignationDropDownList();
            allRadioButton.Checked = false;
            allRadioButton.Text = string.Empty;
            searchButton.Visible = true;
            searchButton.Enabled = true;

        }

        private void PopulatedDesignationDropDownList()
        {

            DesignationManager designationManager = new DesignationManager();
            DataTable designations = designationManager.GetAllEmployeeDesignations();
            designationDropDownList.DataTextField = "Name";
            designationDropDownList.DataValueField = "Id";
            designationDropDownList.DataSource = designations;
            designationDropDownList.DataBind();
        }

        protected void allRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            searchButton.Visible = false;
            PopulatedAllRadioButton();
        }

        private void PopulatedAllRadioButton()
        {
            designationRadioButton.Checked = false;
            designationRadioButton.Text = string.Empty;
            GetAllEmployeeList();


        }

        private void GetAllEmployeeList()
        {
            List<Employee> employees = manager.GetAllEmployeeList();
            employeeGridView.DataSource = employees;
            employeeGridView.DataBind();
        }

 

        protected void searchButton_Click(object sender, EventArgs e)
        {
            int selectedDesignation = Convert.ToInt32(designationDropDownList.SelectedValue);
            List<Employee> employees = manager.GetEmployeeForSelectItem(selectedDesignation);
            employeeGridView.DataSource = employees;
            employeeGridView.DataBind();
        }

        protected void employeeGridView_SelectedIndexChanged(object sender, EventArgs e)
        {

        }



        protected void personalInformationSearchLinkButton_Click(object sender, EventArgs e)
        {

            Response.Redirect("PersonalEmployeeInformationaspx.aspx");
        }



        protected void employeeGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Employee aEmployee = e.Row.DataItem as Employee;

                if (aEmployee != null)
                {
                    HyperLink hpr = (HyperLink)e.Row.FindControl("HyperLinkEdit");

                    hpr.NavigateUrl = "EditEmployee.aspx?id=" + aEmployee.Id.ToString();
                }

                
            }
        }
    }
}